import { Sequelize, DataTypes, Model } from 'sequelize';
import { Application } from '../declarations';
import { HookReturn } from 'sequelize/types/hooks';

export default function (app: Application): typeof Model {
  const sequelizeClient: Sequelize = app.get('sequelizeClient');
  const lend = sequelizeClient.define('lend', {
    // 读者id
    ru_id: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 书籍表id
    book_id: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 借阅书籍===创建时间
    // l_lendT: {
    //   type: DataTypes.STRING,
    //   allowNull: false
    // },
    // 应还时间
    l_returnT: {
      type: DataTypes.STRING,
      allowNull: false
    },
    // 借阅次数
    l_times: {
      type: DataTypes.STRING,
      allowNull: false
    },
    l_realReturnT: {
      type: DataTypes.STRING,
      allowNull: false
    },
  }, {
    hooks: {
      beforeCount(options: any): HookReturn {
        options.raw = true;
      }
    }
  });

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  (lend as any).associate = function (models: any): void {
    // Define associations here
    // See https://sequelize.org/master/manual/assocs.html
  };

  return lend;
}
